// 621 任务调度器
#include <bits/stdc++.h>
using namespace std;

class Solution {
public:
    int leastInterval(vector<char>& tasks, int n) {
        vector<int> vtTask(26,0);
        for(auto c:tasks) vtTask[c-'A']++;
        sort(vtTask.begin(),vtTask.end());

        int i=vtTask.size()-1;
        int maxCnt = vtTask[i];
        int maxCntCnt = 1;
        for(i--; i>=0&&vtTask[i]==vtTask[i+1]; i--,maxCntCnt++);
        return max((int)tasks.size(), (n+1)*(maxCnt-1)+maxCntCnt);
    }
};
